package com.study.leetcode;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Solution_217 {
    public static boolean containsDuplicate(int[] nums) {
        Map<Integer, Integer> numCount = new HashMap<>();
        for (int num : nums) {
            Integer count = numCount.get(num);
            if (count != null) {
                return true;
            } else {
                numCount.put(num, 1);
            }
        }
        return false;
    }

    public static boolean containsDuplicate1(int[] nums) {
        Set<Integer> numSet = new HashSet<>();
        for (int num : nums) {
            if (!numSet.add(num)) {
                return true;
            }
        }
        return numSet.size() < nums.length;
    }

    public static void main(String[] args) {
        int[] nums = {1, 2, 3, 4, 4};
        boolean duplicate = containsDuplicate1(nums);
        System.out.println("duplicate = " + duplicate);
    }
}
